<?php
declare (strict_types = 1);

namespace app\model;

use app\common\service\redis\PoolRedis;
use think\Model;

/**
 * @mixin \think\Model
 */
class AdminStaffData extends Model
{
    //
    public function getLastLoginTimeAttr($value) {
        return $value > 0 ? date('Y-m-d H:i:s', $value) : '';
    }
	
	public function getLastBindDeviceTimeAttr($value) {
        return $value > 0 ? date('Y-m-d H:i', $value) : '';
    }

    public function staff() {
        return $this->belongsTo(AdminStaff::class, 'staff_id');
    }

    public function getStatusTextAttr($value,$data)
{
    $status = [0=>'未绑定',1=>'已绑定',2 => '申请解绑', 3=> '已解绑'];
    return $status[$data['bind_device_status']];
}

    // 获取近t天的日期
    public static function get7day($key, $format='Ymd')
    {
        //组合数据
        $date = [];
        for ($i=0; $i<=7; $i++){
            $date[$i] = $key.date($format ,strtotime( '-' . $i .' days', time()));
        }
        return $date;
    }

    // 把time按指定长度进行分组
    public static function groupTime($splice, $time = 24)
    {
        $arr = [];
        for ($i = 0; $i < $time; $i+=$splice) {
            $arr[] = ['label' => $i."h", 'man' => 0, 'woman' => 0];
        }
        return $arr;
    }
}
